{% extends 'base_blog.html' %}
{% load bootstrap3 %}

{% block title %} Blog {% endblock %}

{% block nav_blog %} class="active" {% endblock %}

{% block blog_list %}

  {% if user_self and not archive_month and not category_tag %}
    <div class="row">
        <div class="pull-right" style="padding-top: 43px;">
          <a href="{% url 'blog:edit' username %}" class="btn btn-primary" role="button">{% bootstrap_icon "plus" %} New blog</a>
        </div>
    </div>
  {% endif %}

  {% for blog in blog_list %}
    <div class="row">
      <div>
        <h2 class="page-header">
          <a href="{% url 'blog:view' username blog.pk%}">
            {{ blog.title }}
          </a>
        </h2>

        <div class="row" style="padding-top: 5px;padding-bottom: 10px">
          <div class="col-md-9">
            <div class="text-left">
              {% for tag in blog.tag.all %}
                {% if tag.tag_name %}
                  <a href="{% url 'blog:category' username tag.tag_name %}" class="btn btn-sm btn-default">{{ tag.tag_name }}</a>
                {% endif %}
              {% endfor %}
            </div>
          </div>

          <div class="col-md-3">
            <div class="text-right">
              <p class="text-muted"> {{ blog.created_time|date:"M. j, Y, H:i:s" }} </p>
            </div>
          </div>
        </div>

        {{ blog.content|safe|truncatewords_html:150 }}
      </div><br><br>

    </div>
  {% endfor %}

{% endblock %}

{% block pagination %}

  {% if pages > 1 %}
    <div class="row">
      <ul class="pagination pagination-lg pull-left">
        {% if page != 1 %}
          <li><a href="{% url 'blog:blog' username last_page %}">&laquo;</a></li>
        {% else %}
          <li class="disabled"><span>&laquo;</span></li>
        {% endif %}

        {% for i in range %}
          {% if i == page %}
            <li class="active"><span>{{ i }}<span class="sr-only">(current)</span></span></li>
          {% else %}
            <li><a href="{% url 'blog:blog' username i %}">{{ i }}</a></li>
          {% endif %}
        {% endfor %}

        {% if page != pages %}
          <li><a href="{% url 'blog:blog' username next_page %}">&raquo;</a></li>
        {% else %}
          <li class="disabled"><span>&raquo;</span></li>
        {% endif %}
      </ul>
    </div>
  {% endif %}

{% endblock %}